<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>原型和原型链</title>
	</head>
	<body>
		<script>
			//在构造函数上直接定义方法（不共享）
			// function Animai(){
			//     this.eat=function(){
			//         console.log("我爱吃饭")
			//     }
			// }
			// let dog=new Animai()
			// let cat=new Animai()

			// dog.eat();//我爱吃饭
			// cat.eat();//我爱吃饭

			// console.log(dog.eat===cat.eat)//false
			//在原型上直接定义方法（共享）
			function Animai() {
				this.name = name
			}
			Animai.prototype.eat = function () {
				console.log('我爱吃饭', this.name)
			}
			let dog = new Animai()
			let cat = new Animai()

			dog.eat() //我爱吃饭
			cat.eat() //我爱吃饭

			console.log(dog.eat===cat.eat)//true
		</script>
	</body>
</html>
